package com.bruce.dao.impl;

import com.bruce.bean.Student;
import com.bruce.dao.StudentDao;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class StudentDaoImpl extends BaseDao implements StudentDao {

    @Override
    public Student studentLogin(Student student) {
        try {
            return queryRunner.query("select * from student where sid=? and spassword=?",
                    new BeanHandler<Student>(Student.class),student.getSid(),student.getSpassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int addStudent(Student student) {
        String sql = "insert into student values (?,?,?,?,?,?,?,?,?)";
        Object[] params = {student.getSid(),student.getSname(),student.getSidcard(),student.getSsex(),student.getSpassword(),student.getSage(),student.getClassr(),student.getProfession(),student.getCollege()};
        int update =0;
        try {
             update = queryRunner.update(sql, params);
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
            return -1;
        }
        return update;
    }
}
